package com.axend.aerosense.room.ui.activity;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.gyf.immersionbar.ImmersionBar;
import com.axend.aerosense.base.activity.MvvmBaseActivity;
import com.axend.aerosense.base.bean.RoomTypeBean;
import com.axend.aerosense.base.viewmodel.BaseViewModel;
import com.axend.aerosense.common.base.IToolBarTextClickListence;
import com.axend.aerosense.common.util.FragmentUtil;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomActivitySaveModelBinding;
import com.axend.aerosense.room.ui.fragment.RoomNameFragment;
import com.axend.aerosense.room.ui.fragment.RoomTypeListFragment;

public class SaveModelActivity extends MvvmBaseActivity<RoomActivitySaveModelBinding, BaseViewModel> {
    public static final String OPEN_MODE_ROOM_NAME = "OPEN_MODE_ROOM_NAME";
    public static final String OPEN_MODE_ROOM_ID = "OPEN_MODE_ROOM_ID";
    public static final String OPEN_MODE_ROOM_TYPE = "OPEN_MODE_ROOM_TYPE";
    public static final String OPEN_TYPE = "OPEN_TYPE";
    public static final int OPEN_TYPE_SET_NAME = 0;
    public static final int OPEN_TYPE_SET_ROOM_TYPE = 1;
    public static final int REQUEST_CODE_SET_NAME = 512;
    public static final int REQUEST_CODE_SET_TYPE = 513;

    private int openType = 0;
    private String roomOldName = "";
    private RoomTypeBean oldRoomTypeBean;
    private RoomNameFragment roomNameFragment = null;
    private Fragment currentFragment = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this)
                .statusBarColor(android.R.color.white)
                .fitsSystemWindows(true)
                .statusBarDarkFont(true)
                .autoDarkModeEnable(true).init();
//        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
//        getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
        openType = getIntent().getIntExtra(OPEN_TYPE, OPEN_TYPE_SET_NAME);
        roomOldName = getIntent().getStringExtra(OPEN_MODE_ROOM_NAME);
        oldRoomTypeBean = (RoomTypeBean) getIntent().getSerializableExtra(OPEN_MODE_ROOM_TYPE);

        if(OPEN_TYPE_SET_NAME == openType){
            viewDataBinding.roomToolTitle.setText(R.string.room_name);
            String roomUuid = getIntent().getStringExtra(OPEN_MODE_ROOM_ID);
            // 如果roomUuid 不为空表示是编辑模式
            currentFragment = RoomNameFragment.newInstance(roomOldName, roomUuid);

        }else {
            viewDataBinding.roomToolTitle.setText(R.string.room_type);
            currentFragment = RoomTypeListFragment.newInstance(oldRoomTypeBean);
        }

        FragmentUtil.add(this, viewDataBinding.roomContentView.getId(), currentFragment, null, false);

        viewDataBinding.roomToolCancel.setOnClickListener(v->{
            ((IToolBarTextClickListence)currentFragment).onCancel();
        });

        viewDataBinding.roomToolSure.setOnClickListener(v->{
            ((IToolBarTextClickListence)currentFragment).onSure();
        });
    }


    @Override
    protected BaseViewModel getViewModel() {
        return null;
    }

    @Override
    protected int getBindingVariable() {
        return 0;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.room_activity_save_model;
    }

    @Override
    protected void onRetryBtnClick() {

    }
}